Announcement

Collapse
No announcement yet.

Removing global variables when “Edit Studies” is run to change globals name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Removing global variables when “Edit Studies” is run to change globals name

    I have modified the “LinesLables.efs” by adding a menu item in preMain() that allows me to change the name of the global variables. The idea is to allow me to have two of these scripts running in the same chart increasing the number of lines to 60 with each efs (30 lines) having a different ID tag for the global variables. (note: I have successfully increased the # of lines to 50 and above but prefer the above method because it allows more flexibility)

    It works fine except that the global variables are not cleared when I change the ID tag (via Edit Studies) so other charts with different intervals that use the efs to draw lines reflect the old and new lines instead of just the new lines.

    Placing “removeGlobalValue(xxx)” in postMain() doesn’t do the trick nor have I successfully added a removeGlobalValue(xxx) right after the "if (vLoaded == false) {" because I can't capture the old ID tags.

    As I understand it, when I change anything via “Edit Studies” it reloads the efs but it doesn’t seem to trigger postMain().

    Question:

    How do I clear the old global variables when I change their unique ID via “Edit Studies”?

    Thanks in advance.

    Wayne

    My version of LinesLables.efs is attached
    PHP Code:
    /*****************************************************************
    Provided By : eSignal. (c) Copyright 2003
    Study:        Lines and Labels
    Version:      2.0

    2.0 Updates - 12/18/2003
    *Added FunctionParameter class for user inputs.
    *Changed naming convention for the global variables
     associated with vEditing to be symbol specific.  This allows
     the formula to be used with multiple sets of charts using
     different symbols.  Only charts with the same symbol will
     share the same price levels for the lines.
    *Added setShowTitleParameters(false) to hide formula parameters
     from the study title.
    *Added function parameter, Display Labels, to toggle the display 
     of the labels to ON/OFF.
    *Added function parameter, Label Position, to set labels to appear
     on the left side of the chart or to the right.  If set to right, 
     the labels will appear on bar index 2 just right of the current bar.
    *Added sharing of the main chart's formatting options for, Thickness,
     Color, Display and Position.

    Notes:
    *Formula requires version 7.5.
    *Draws up to 30 Horizontal Lines with optional labels.
    *vEditing option allows the main chart where the price levels 
     for the lines are set to be shared with additional charts
     using the same symbol.  The additional charts only need to
     have this formula running.  The price levels only need to be set
     once from the main chart.  To enable this feature, set vEditing
     to true in the main chart.  After making subsequent changes in the
     main chart, the other charts' LinesLabel
     
     user changes 20090722: added  a user defined ID for global variables-still 
    has bugs-previous globals are not cleared when the ID tag is changed
    *****************************************************************/

    var aFPArray    = new Array();
    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Line & Labels MP Color-30var");
        
    setShowTitleParameters(false);
        
    var 
    x=0
        
    aFPArray[x] = new FunctionParameter("vVAR"FunctionParameter.STRING);
        
    withaFPArray[x++] ) {
            
    setName("Variable Label ID");
            
    addOption("g");
            
    addOption("h");
            
    addOption("i");
            
    addOption("j");
            
    addOption("k");
            
    setDefault("g");
        }
        
    aFPArray[x] = new FunctionParameter("vEditing"FunctionParameter.BOOLEAN);
        
    withaFPArray[x++] ) {
            
    setName("vEditing (share lines w/ other charts)");
            
    setDefault(false);
        }
        
    aFPArray[x] = new FunctionParameter("BandDisplay"FunctionParameter.STRING);
        
    withaFPArray[x++] ) {
            
    setName("Display Bands");
            
    addOption("ON");
            
    addOption("OFF");
            
    setDefault("ON");
        }
        
    aFPArray[x] = new FunctionParameter("LabelDisplay"FunctionParameter.STRING);
        
    withaFPArray[x++] ) {
            
    setName("Display Labels");
            
    addOption("ON");
            
    addOption("OFF");
            
    setDefault("ON");
        }
        
    aFPArray[x] = new FunctionParameter("bLDisplay"FunctionParameter.STRING);
        
    withaFPArray[x++] ) {
            
    setName("Display Global Labels");
            
    addOption("ON");
            
    addOption("OFF");
            
    setDefault("ON");
        }
        
    aFPArray[x] = new FunctionParameter("sLabelPos"FunctionParameter.STRING);
        
    withaFPArray[x++] ) {
            
    setName("Label Position");
            
    addOption("Left");
            
    addOption("Right");
            
    setDefault("Left");
        }
        
    aFPArray[x] = new FunctionParameter("LLabelOffset"FunctionParameter.NUMBER);
        
    withaFPArray[x++] ) {
            
    setName("Left Label Offset");
            
    setLowerLimit(0);
            
    setUpperLimit(20); 
            
    addOption(0);
            
    setDefault(0);
        }
        
    aFPArray[x] = new FunctionParameter("RLabelOffset"FunctionParameter.NUMBER);
        
    withaFPArray[x++] ) {
            
    setName("Right Label Offset");
            
    setLowerLimit(0);
            
    setUpperLimit(40); 
            
    addOption(10);
            
    setDefault(10);
        }
        
    aFPArray[x] = new FunctionParameter"ShowCursorLabel"FunctionParameter.BOOLEAN); 
        
    withaFPArray[x++] ) { 
            
    setName"Show Cursor Label" ); 
            
    setDefaultfalse ); 
        }       
        var 
    afp1 = new Array(31);
        
    afp1[0] = "";
        var 
    afp2 = new Array(31);
        
    afp2[0] = "";
        var 
    afp3 = new Array(31);
        
    afp3[0] = "";
        var 
    afp4 = new Array(31);
        
    afp4[0] = "";
        var 
    1;
        for (
    131; ++i) {
            var 
    "L"+i;
            
    afp1[i] = new FunctionParameter(LFunctionParameter.NUMBER);
            
    afp1[i].setName("Line " i);
            var 
    Ll "L"+i+"label";
            
    afp2[i] = new FunctionParameter(LlFunctionParameter.STRING);
            
    afp2[i].setName("Line " " Label");
            
    afp2[i].setDefault(" ");
            var 
    "L"+i+"color";
            
    afp3[i] = new FunctionParameter(CFunctionParameter.COLOR);
            
    afp3[i].setName("Line " " Color");
            
    afp3[i].setDefault(Color.blue);
            var 
    "L"+i+"thickness";
            
    afp4[i] = new FunctionParameter(TFunctionParameter.NUMBER);
            
    afp4[i].setName("Line " " Thickness");
                
    afp4[i].setLowerLimit); 
                
    afp4[i].setUpperLimit);
                
    afp4[i].addOption); 
                
    afp4[i].addOption); 
                
    afp4[i].addOption); 
                
    afp4[i].addOption); 
                
    afp4[i].addOption); 
                
    afp4[i].setDefault);
        }
    }

    var 
    vLoaded false;
    var 
    vEdit null;
    var 
    vSym null;
    var 
    bGlobals false;
    var 
    vThi null;
    var 
    vCol null;
    var 
    vDis null;
    var 
    vPos null;
    debugClear();
    var 
    vtxt = -1;
    var 
    vVarGlobal null;

    function 
    main(vVAR,vEditing,ShowCursorLabel,BandDisplay,LabelDisplay,bLDisplay,sLabelPos,LLabelOffset,RLabelOffset,
                  
    L1L1labelL1colorL1thicknessL2L2labelL2colorL2thicknessL3
                  
    L3labelL3colorL3thicknessL4L4labelL4colorL4thicknessL5L5label
                  
    L5colorL5thicknessL6L6labelL6colorL6thicknessL7L7labelL7color
                  
    L7thicknessL8L8labelL8colorL8thickness,  L9L9labelL9colorL9thickness
                  
    L10L10labelL10colorL10thicknessL11L11labelL11colorL11thicknessL12
                  
    L12labelL12colorL12thicknessL13L13labelL13colorL13thicknessL14L14label
                  
    L14colorL14thicknessL15L15labelL15colorL15thicknessL16L16labelL16color
                  
    L16thicknessL17L17labelL17colorL17thicknessL18L18labelL18color
                  
    L18thickness,  L19L19labelL19colorL19thicknessL20L20labelL20color
                  
    L20thicknessL21L21labelL21colorL21thicknessL22L22labelL22color
                  
    L22thicknessL23L23labelL23colorL23thickness,  L24L24labelL24color
                  
    L24thicknessL25L25labelL25colorL25thicknessL26L26labelL26color
                  
    L26thicknessL27L27labelL27colorL27thicknessL28L28labelL28color
                  
    L28thickness,  L29L29labelL29colorL29thicknessL30L30labelL30color
                  
    L30thickness) {
                 
        var 
    sTextFlags null;
        var 
    nTextX 0;
        
    setShowCursorLabel(ShowCursorLabel); 
        
        if (
    vSym == nullvSym getSymbol();
        
        if (
    vLoaded == false) {
            for (
    1<= 30; ++i) {
                var 
    vDataLabel "L" "label";
                
    removeText(vDataLabel);
                
    removeBand(vDataLabel);
                
    removeGlobalValue(vSym vVarGlobal "L"+i);
                
    removeGlobalValue(vSym vVarGlobal "L"+i+"label");
                
    removeGlobalValue(vSym vVarGlobal "L"+i+"color");
                
    removeGlobalValue(vSym vVarGlobal "L"+i+"thickness");
                }
            
    vVarGlobal vVAR;
            if (
    vEditing == true) {
                
    vEdit true;
            } else if (
    vEditing == false) {
                
    vEdit false;
            } else {
                
    vEdit false;
            }
            if (
    vEdit == true) { // share formatting options
                
    setGlobalValue(vSym vVAR "LDisplay"bLDisplay);
                
    setGlobalValue(vSym vVAR "LabelPos"sLabelPos);
            }
            for (
    1<= 30; ++i) {
                var 
    vData "L" i;
                var 
    vDataLabel "L" "label";
                var 
    vLabelColor "L" "color";
                var 
    vLabelThickness "L" "thickness";
                var 
    gData getGlobalValue(vSym vVAR vData);
                var 
    gDataLabel getGlobalValue(vSym vVAR vDataLabel);
                var 
    gLabelColor getGlobalValue(vSym vVAR vLabelColor);

                var 
    gLabelThickness getGlobalValue(vSym vVAR vLabelThickness);
                if (eval(
    vData) != null) {
                    if (
    vEdit == true) { // Current Chart is sharing inputs.
                        
    setGlobalValue(vSym vVAR "L"+i, eval(vData));
                        if (eval(
    vDataLabel) == null) {
                            
    setGlobalValue(vSym vVAR "L"+i+"label""null");
                        } else {
                            
    setGlobalValue(vSym vVAR "L"+i+"label", eval(vDataLabel));
                        }
                        if (eval(
    vLabelColor) == null) {
                            
    setGlobalValue(vSym vVAR "L"+i+"color""null");
                        } else {
                            
    setGlobalValue(vSym vVAR "L"+i+"color", eval(vLabelColor));
                        }
                        if (eval(
    vLabelThickness) == null) {
                            
    setGlobalValue(vSym vVAR "L"+i+"thickness""null");
                        } else {
                            
    setGlobalValue(vSym vVAR "L"+i+"thickness", eval(vLabelThickness));
                        }
                    }
                    if(
    BandDisplay == "ON"addBand(eval(vData), PS_SOLID, eval(vLabelThickness), eval(vLabelColor), vDataLabel);
                    if (
    bLDisplay == "ON") {
                        if (
    sLabelPos == "Right") {
                            
    sTextFlags "Text.LEFT|Text.ONTOP|Text.VCENTER|Text.Bold|Text.FRAME";
                            
    nTextX RLabelOffset;
                        } else {
                            
    sTextFlags "Text.RELATIVETOLEFT|Text.ONTOP|Text.VCENTER|Text.Bold|Text.FRAME";
                            
    nTextX LLabelOffset;
                        }
                        if(
    LabelDisplay == "ON"drawTextAbsolute(nTextX, eval(vData), " " + eval(vDataLabel) + " "
                            
    Color.white, eval(vLabelColor), eval(sTextFlags), null10vDataLabel);
                    }
                } else if (
    vEdit == true) {
                    
    removeText(vDataLabel);
                    
    removeBand(vDataLabel);
                    
    removeGlobalValue(vSym vVAR "L"+i);
                    
    removeGlobalValue(vSym vVAR "L"+i+"label");
                    
    removeGlobalValue(vSym vVAR "L"+i+"color");
                    
    removeGlobalValue(vSym vVAR "L"+i+"thickness");
                }
                
    // Current chart is not sharing but another chart is.
                
    if (vEdit == false && eval(vData) == null && getGlobalValue(vSym vVAR "L"+i) != null) {
                    if (
    bGlobals == false) {
                        
    vDis getGlobalValue(vSym vVAR "LDisplay");
                        if (
    vDis == nullvDis bLDisplay;
                        
    vPos getGlobalValue(vSym vVAR "LabelPos");
                        if (
    vPos == nullvPos sLabelPos;                    
                        
    bGlobals true;
                    }
    //                addBand(gData, PS_SOLID, vThi, vCol, gDataLabel);
                    
    if(BandDisplay == "ON"addBand(gDataPS_SOLIDgLabelThicknessgLabelColorgDataLabel);
                    if (
    vDis == "ON") {
                        if (
    vPos == "Right") {
                            
    sTextFlags "Text.LEFT|Text.ONTOP|Text.VCENTER|Text.Bold|Text.FRAME";
                            
    nTextX 2;
                        } else {
                            
    sTextFlags "Text.RELATIVETOLEFT|Text.ONTOP|Text.VCENTER|Text.Bold|Text.FRAME";
                            
    nTextX 0;
                        }
                        if(
    LabelDisplay == "ON"drawTextAbsolute(nTextXgData" " gDataLabel " "Color.white
                            
    gLabelColor, eval(sTextFlags), null10vDataLabel);
                    }
                }
            }
            
    vLoaded true;
        }
        return;
    }
    /*function postMain(){
            for (i = 1; i <= 30; ++i) {
    //        if(vEdit == false){//true){//reloadEFS()
                var vDataLabel = "L" + i + "label";
    //            removeText(vDataLabel);//only used in main()
                removeBand(vDataLabel);
                removeGlobalValue(vSym + vVarGlobal + "L"+i);
                removeGlobalValue(vSym + vVarGlobal + "L"+i+"label");
                removeGlobalValue(vSym + vVarGlobal + "L"+i+"color");
                removeGlobalValue(vSym + vVarGlobal + "L"+i+"thickness");
    //        }
                }
    }*/ 
    Last edited by waynecd; 07-22-2009, 08:59 AM.

  • #2
    To simplify:

    Is there a way, in "function main()" to identify when there are changes in the menu via "Edit Studies"?

    Or, can gobal variables be removed by just using the begining of the name, something like "removeGlobalValue( vSym* )"? This way I could use the charts symbol to delete all global variables whose name start with the chart symbol.

    Or, can I keep a variables value through an "Edit Studies" routine? I've tried this with no success. See below:

    PHP Code:
    var vVAR_Old null;

    function 
    main(vVAR);//vVAR is the unique identifier used to ID global variable names
        
    if (vLoaded == false) {
            if(
    vVAR_Old == nullvVAR_Old vVAR;
            else if(
    vVAR_Old != vVAR){
                for (
    1<= 50; ++i) {
                    
    removeText(vDataLabel);
                    
    removeBand(vDataLabel);
                    
    removeGlobalValue(vSym vVAR_Old "L"+i);
                    
    removeGlobalValue(vSym vVAR_Old "L"+i+"label");
                    
    removeGlobalValue(vSym vVAR_Old "L"+i+"color");
                    
    removeGlobalValue(vSym vVAR_Old "L"+i+"thickness");
                }
                 
    vVAR_Old vVAR;
           }
            ...
    etc
            vLoaded 
    true;
         } 
    Even when I close the efs that is creating and sharing the global variables the other charts with the efs and even new charts on which I load the efs after deleting the sharing the global variables still exist. So the post Main() does not affect the created global variables. The post Main() function below does not remove the varibles:
    PHP Code:
    function postMain(){
            for (
    1<= 50; ++i) {
                var 
    vData "L" i;
                var 
    vDataLabel "L" "label";
                var 
    vLabelColor "L" "color";
                var 
    vLabelThickness "L" "thickness";
    //            removeText(vDataLabel); //can only be called in main()
                
    removeBand(vDataLabel);
                
    removeGlobalValue(vSym vVAR "L"+i);
                
    removeGlobalValue(vSym vVAR "L"+i+"label");
                
    removeGlobalValue(vSym vVAR "L"+i+"color");
                
    removeGlobalValue(vSym vVAR "L"+i+"thickness");
            }

    Thanks

    Wayne
    Last edited by waynecd; 07-22-2009, 08:27 PM.

    Comment


    • #3
      disregard.

      Figured it out. I just needed to make the ID varible in "post Main()" a global variable in conjuction with keeping the last ID variable through the change made to it via "Edit Studies".

      Comment

      Working...
      X